# coding=utf-8
import csv


class GetData(object):
    # base_file_path = u"../data/data_block_"
    # todo 服务器上线必改
    base_file_path = u"/home/g304/MengLie/crawlTest/data/data_block_"

    @classmethod
    def get_data_from_orial(self, block_num=1):
        # todo 服务器上线必改
        base_path = u"/home/g304/MengLie/crawlTest/export/scholarInfo/"
        # base_path = u"/scrapy/export/scholarInfo/"
        f = open(base_path + str(block_num) + ".csv", "rb")
        csvDict = csv.DictReader(f)
        myDict = []
        for csvrow in csvDict:
            myDict.append(dict(scholarId = csvrow['scholarId'].decode("gb18030"),
                               personName = csvrow['personName'].decode("gb18030"),
                               entityId  = csvrow['entityId'].decode("gb18030")
                               ))
        return myDict

    @classmethod
    def get_orial_data_block(cls, block_num=1):
        f = open(GetData.base_file_path + str(block_num) + ".csv", "rb")
        csvDict = csv.DictReader(f)
        myDict = []
        for csvrow in csvDict:
            myDict.append(dict(scholar=csvrow['ZJXM'].decode("gb18030"),
                               school=csvrow['ZJXX'].decode("gb18030"),
                               major=csvrow['ZJXY'].decode("gb18030"),
                               scholarNo=csvrow['ZJBH'].decode("gb18030")))

        return myDict
    @classmethod
    def get_more_paper_data_block(self, block_num=1):
        # filePath = u"/home/g304/MengLie/crawlTest/export/paperInfo/"
        filePath = u"D:\\data\\"
        f = open(filePath + str(block_num) + ".csv", "rb")
        csvDict = csv.DictReader(f)
        myDict = []
        for csvrow in csvDict:
            myDict.append(dict(paperID =csvrow['paperID'].decode("gb18030"),
                               entityId=csvrow['entityId'].decode("gb18030"),
                               paperName=csvrow['paperName'].decode("gb18030"),
                               paperAuthor=csvrow['personName'].decode("gb18030"),
                               paperTime =csvrow['paperTime'].decode("gb18030"),
                               baiduLink = csvrow['paperLink'].decode("gb18030"),

                               paperLink = []))

        return myDict